<?php


namespace app\common\model;


use think\model;

class Record extends Model
{
    //  连接数据库
    protected $connection = 'mysql';
    //  连接表名
    protected $name = 'record';
    //  自动写入时间戳字段
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';

    // 分页查询,获取列表
    public function fetchListByWhere($where, $order = ['id' => 'desc'], $field = '*', $page = 1, $pageSize = 10)
    {
        return $this->field($field)->where($where)->order($order)->page($page, $pageSize)->select()->toArray();
    }

    //关联单元
    public function unit()
    {
        return $this->hasOne(Unit::class, 'id', 'unit_id')->field('id,title');
    }

    //关联前台用户表
    public function apimember()
    {
        return $this->hasOne(ApiMember::class, 'id', 'api_member_id')->field('id,nickname');
    }

    //关联前台用户表
    public function backmember()
    {
        return $this->hasOne(BackendMember::class, 'id', 'backend_member_id')->field('id,username');
    }

    //关联资料表
    public function datum()
    {
        return $this->hasOne(Datum::class, 'id', 'datum_id')->field('id,title');
    }

    //关联学习中心表
    public function datumcate()
    {
        return $this->hasOne(DatumCate::class, 'id', 'datum_cate_id')->field('id,title');
    }
}